<?php
class AssetExportController extends Zone_Action{
	public function indexAction(){
		$this->removeLayout();
		$user_id = get_user_id();
		$ids = get('ID',array(),true);

		if( count($ids) == 0 ){
			return $this->setContent("<script> parent.$.Alert('Chưa có tài sản nào được chọn.'); </script>");
		}else{
		$ids = join(",",$ids);	
		$posts = $this->Model->fetchAll("
		SELECT `a`.* 
		FROM `assets` as `a`
		WHERE `a`.`ID` in ($ids)
		");		
	
	header("Content-type: application/excel; charset=utf8");
    header('Content-disposition: attachment; filename="Tài_sản ('.date("d-m-Y H:i:s").').xls"');
	echo '<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:html="http://www.w3.org/TR/REC-html40">
 <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
  <Version>12.00</Version>
 </DocumentProperties>
 <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
  <WindowHeight>8505</WindowHeight>
  <WindowWidth>19155</WindowWidth>
  <WindowTopX>0</WindowTopX>
  <WindowTopY>30</WindowTopY>
  <ProtectStructure>False</ProtectStructure>
  <ProtectWindows>False</ProtectWindows>
 </ExcelWorkbook>
 <Styles>
  <Style ss:ID="Default" ss:Name="Normal">
   <Alignment ss:Vertical="Bottom"/>
   <Borders/>
   <Font ss:FontName="Arial" x:Family="Swiss"/>
   <Interior/>
   <NumberFormat/>
   <Protection/>
  </Style>
  <Style ss:ID="s62" ss:Name="Hyperlink">
   <Font ss:FontName="Arial" x:Family="Swiss" ss:Color="#0000FF"
    ss:Underline="Single"/>
  </Style>
  <Style ss:ID="s63" ss:Name="Normal 3">
   <Alignment ss:Vertical="Bottom"/>
   <Borders/>
   <Font ss:FontName="Arial" x:Family="Swiss"/>
   <Interior/>
   <NumberFormat/>
   <Protection/>
  </Style>
  <Style ss:ID="s64">
   <Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
  </Style>
  <Style ss:ID="s66" ss:Parent="s63">
   <Alignment ss:Horizontal="Center" ss:Vertical="Center"/>
   <Font ss:FontName="Times New Roman" x:Family="Roman" ss:Size="12"/>
   <Interior/>
   <NumberFormat/>
  </Style>
  <Style ss:ID="s68">
   <Alignment ss:Horizontal="Center" ss:Vertical="Center"/>
   <Font ss:FontName="Times New Roman" x:Family="Roman" ss:Size="16" ss:Bold="1"/>
   <Interior/>
  </Style>
  <Style ss:ID="s69" ss:Parent="s63">
   <Alignment ss:Horizontal="Left" ss:Vertical="Center"/>
   <Font ss:FontName="Times New Roman" x:Family="Roman" ss:Size="12"/>
   <Interior/>
  </Style>
  <Style ss:ID="s70" ss:Parent="s63">
   <Alignment ss:Horizontal="Center" ss:Vertical="Center"/>
   <Font ss:FontName="Times New Roman" x:Family="Roman" ss:Size="12"/>
   <Interior/>
  </Style>
  <Style ss:ID="s71">
   <Alignment ss:Horizontal="Center" ss:Vertical="Center"/>
   <Font ss:FontName="Times New Roman" x:Family="Roman" ss:Size="13" ss:Bold="1"/>
   <Interior/>
  </Style>
  <Style ss:ID="s72">
   <Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:ShrinkToFit="1"/>
   <Font ss:FontName="Times New Roman" x:Family="Roman" ss:Size="13" ss:Bold="1"/>
   <Interior/>
  </Style>
  <Style ss:ID="s73" ss:Parent="s63">
   <Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:WrapText="1"/>
   <Borders>
    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
   </Borders>
   <Font ss:FontName="Arial" x:Family="Swiss" ss:Size="11" ss:Color="#333333"
    ss:Bold="1"/>
   <Interior ss:Color="#D8D8D8" ss:Pattern="Solid"/>
  </Style>
  <Style ss:ID="s74" ss:Parent="s63">
   <Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:ShrinkToFit="1"/>
   <Borders>
    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
   </Borders>
   <Font ss:FontName="Arial" x:Family="Swiss" ss:Size="11" ss:Color="#333333"
    ss:Bold="1"/>
   <Interior ss:Color="#D8D8D8" ss:Pattern="Solid"/>
  </Style>
  <Style ss:ID="s75">
   <Alignment ss:Horizontal="Center" ss:Vertical="Center" ss:ShrinkToFit="1"/>
   <Borders>
    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
   </Borders>
   <Font ss:FontName="Arial" x:Family="Swiss" ss:Size="11" ss:Color="#333333"
    ss:Bold="1"/>
   <Interior ss:Color="#D8D8D8" ss:Pattern="Solid"/>
  </Style>
  <Style ss:ID="s76">
   <Alignment ss:Horizontal="Center" ss:Vertical="Center"/>
   <Borders>
    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
   </Borders>
   <Font ss:FontName="Arial" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
  </Style>
  <Style ss:ID="s77">
   <Alignment ss:Horizontal="Left" ss:Vertical="Center"/>
   <Borders>
    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
   </Borders>
   <Font ss:FontName="Arial" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
  </Style>
  <Style ss:ID="s78">
   <Alignment ss:Horizontal="Center" ss:Vertical="Center"/>
   <Borders>
    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
   </Borders>
   <Font ss:FontName="Arial" x:Family="Swiss" ss:Size="11" ss:Color="#000000"/>
   <NumberFormat ss:Format="0%"/>
  </Style>
  <Style ss:ID="s80" ss:Parent="s62">
   <Alignment ss:Horizontal="Center" ss:Vertical="Center"/>
   <Borders>
    <Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>
    <Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>
   </Borders>
   <Protection/>
  </Style>
 </Styles>
 <Worksheet ss:Name="Sheet1">
  <Table x:FullColumns="1">
   <Column ss:Width="27.75"/>
   <Column ss:Width="144"/>
   <Column ss:Width="129.75"/>
   <Column ss:Width="66.75"/>
   <Column ss:Width="117"/>
   <Column ss:Width="97.5"/>
   <Column ss:AutoFitWidth="0" ss:Width="81.75"/>
   <Column ss:StyleID="s64" ss:AutoFitWidth="0" ss:Width="120.75"/>
   <Column ss:AutoFitWidth="0" ss:Width="200.25"/>
   <Column ss:AutoFitWidth="0" ss:Width="140.25"/>
   <Column ss:AutoFitWidth="0" ss:Width="203.25"/>
   <Row ss:AutoFitHeight="0" ss:Height="21.75">
    <Cell ss:StyleID="s66"/>
    <Cell ss:MergeAcross="3" ss:StyleID="s68"><Data ss:Type="String">       DANH SÁCH TÀI SẢN</Data></Cell>
    <Cell ss:StyleID="s69"/>
    <Cell ss:StyleID="s69"/>
    <Cell ss:StyleID="s70"/>
    <Cell ss:StyleID="s69"/>
    <Cell ss:StyleID="s69"/>
   </Row>
   <Row ss:AutoFitHeight="0" ss:Height="16.5">
    <Cell ss:StyleID="s71"/>
    <Cell ss:StyleID="s71"/>
    <Cell ss:Index="4" ss:StyleID="s71"/>
    <Cell ss:StyleID="s72"/>
    <Cell ss:StyleID="s72"/>
    <Cell ss:StyleID="s72"/>
    <Cell ss:StyleID="s72"/>
    <Cell ss:StyleID="s72"/>
    <Cell ss:StyleID="s72"/>
   </Row>
   <Row ss:AutoFitHeight="0">
    <Cell ss:StyleID="s73"><Data ss:Type="String">TT</Data></Cell>
    <Cell ss:StyleID="s73"><Data ss:Type="String">Tên tài sản</Data></Cell>
    <Cell ss:StyleID="s73"><Data ss:Type="String">Hãng SX</Data></Cell>
    <Cell ss:StyleID="s74"><Data ss:Type="String">Model</Data></Cell>
    <Cell ss:StyleID="s75"><Data ss:Type="String">Ngày mua</Data></Cell>
    <Cell ss:StyleID="s75"><Data ss:Type="String">Giá</Data></Cell>
    <Cell ss:StyleID="s75"><Data ss:Type="String">Mã bảo hành</Data></Cell>
    <Cell ss:StyleID="s75"><Data ss:Type="String">Thời gian bảo hành</Data></Cell>
    <Cell ss:StyleID="s75"><Data ss:Type="String">Địa điểm mua</Data></Cell>
    <Cell ss:StyleID="s75"><Data ss:Type="String">Hiện trạng</Data></Cell>
    <Cell ss:StyleID="s75"><Data ss:Type="String">Mô tả</Data></Cell>
   </Row>';
   
  foreach( $posts as  $k => $post ){
	   echo ' 
	    <Row ss:AutoFitHeight="0">
    <Cell ss:StyleID="s76"><Data ss:Type="Number">'.($k+1).'</Data></Cell>
    <Cell ss:StyleID="s77"><Data ss:Type="String">'.$post["title"].'</Data></Cell>
    <Cell ss:StyleID="s76"><Data ss:Type="String">'.$post["origin"].'</Data></Cell>
    <Cell ss:StyleID="s76"><Data ss:Type="String">'.$post["model"].'</Data></Cell>
    <Cell ss:StyleID="s76"><Data ss:Type="String">'.show-date(DATE_FORMAT,$post["datebuy"]).'</Data></Cell>
    <Cell ss:StyleID="s78"><Data ss:Type="String">'.$post["value"].'</Data></Cell>
    <Cell ss:StyleID="s80" ><Data
      ss:Type="String">'.$post["codesu"].'</Data></Cell>
    <Cell ss:StyleID="s76"><Data ss:Type="Number">'.$post["time"].'</Data></Cell>
    <Cell ss:StyleID="s76"><Data ss:Type="String">'.$post["buyat"].'t</Data></Cell>
    <Cell ss:StyleID="s76"><Data ss:Type="String">'.$post["status"].'</Data></Cell>
    <Cell ss:StyleID="s76"><Data ss:Type="String">'.$post["desc"].'</Data></Cell>
   ';
   
	}
	
  echo '</Table>
  <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
   <PageSetup>
    <Header x:Margin="0.3"/>
    <Footer x:Margin="0.3"/>
    <PageMargins x:Bottom="0.75" x:Left="0.7" x:Right="0.7" x:Top="0.75"/>
   </PageSetup>
   <Unsynced/>
   <Selected/>
   <TopRowVisible>1</TopRowVisible>
   <Panes>
    <Pane>
     <Number>3</Number>
     <ActiveRow>13</ActiveRow>
     <ActiveCol>10</ActiveCol>
    </Pane>
   </Panes>
   <ProtectObjects>False</ProtectObjects>
   <ProtectScenarios>False</ProtectScenarios>
  </WorksheetOptions>
 </Worksheet>
</Workbook>

';
	exit;
	}		
}}	